package com.jiang.gzjp.struts.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.jiang.gzjp.struts.form.DeptForm;
import com.jiang.gzjp.struts.vo.Dept;

/**
 * MyEclipse Struts Creation date: 02-28-2019
 * 
 * XDoclet definition:
 * 
 * @struts.action path="/dept" name="deptForm" input="/form/dept.jsp"
 *                parameter="status" scope="request" validate="true"
 */
public class DeptAction extends DispatchAction {
	/*
	 * Generated Methods
	 */

	public ActionForward insert(ActionMapping mapping, ActionForm form, HttpServletRequest request,HttpServletResponse response){
		
		System.out.println("增加部门!");
		return null;
	}
	
	public ActionForward list(ActionMapping mapping, ActionForm form, HttpServletRequest request,HttpServletResponse response){
		System.out.println("查询部门成功!");
		
		Dept dept = new Dept();
		dept.setDeptno(500);
		dept.setDname("外围测试");
		// 这里没有双向绑定，只能靠request去传递
		request.setAttribute("dept", dept);
		List<Dept> all = new ArrayList<Dept>();
		for(int i=0;i<10;i++){
			dept = new Dept();
			dept.setDeptno(i);
			dept.setDname("jzw"+i);
			all.add(dept);
		}
		request.setAttribute("all", all);
		return mapping.findForward("success"); // 这里的跳转都是服务器端的跳转
	}
	
	public ActionForward update(ActionMapping mapping, ActionForm form, HttpServletRequest request,HttpServletResponse response){
		
		System.out.println("修改部门!");
		DeptForm deptForm = (DeptForm)form;
		deptForm.getDept().setDeptno(222);
		deptForm.getDept().setDname("张瑞峰");
		
		return mapping.findForward("success"); 
	}
	

}